package com.example.zxingdemo.base;

import android.app.Activity;
import android.os.Bundle;

import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;

import com.example.zxingdemo.util.PermissionUtil;
import static com.example.zxingdemo.config.RequestCode.PERMISSION_REQUEST;

public class BaseActivity extends AppCompatActivity implements PermissionUtil.PermissionListener {
    private PermissionUtil permissionUtil;
    private String[] permission = {"android.permission.CAMERA","android.permission.WRITE_EXTERNAL_STORAGE"};

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        permissionUtil = new PermissionUtil(this);
        requestPermission(permission,PERMISSION_REQUEST);
    }

    protected void requestPermission(String[] permissions, int permissionCode){
        if (permissionUtil == null)
            return;
        permissionUtil.requestPermission(permissions,permissionCode,this);
    }

    @Override
    public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
        super.onRequestPermissionsResult(requestCode, permissions, grantResults);
        if (permissionUtil != null){
            permissionUtil.premissionCallBack(requestCode,grantResults);
        }
    }

    @Override
    public void permissionSuccess(int requestCode) {

    }

    @Override
    public void permissionFail(int requestCode) {

    }
}
